package es.ats.codington.web.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import es.ats.codington.festival.services.EventSingUpService;

/**
 * Servlet implementation class RegisterInEventServlet.
 */
@WebServlet("/RegisterInEventServlet")
public class RegisterInEventServlet extends HttpServlet {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;
       
    /**
     * Instantiates a new register in event servlet.
     *
     * @see HttpServlet#HttpServlet()
     */
    public RegisterInEventServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * Do get.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * Do post.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession(true);
		int IdEvent = Integer.parseInt(request.getParameter("Id"));
		int IdVisitor =(Integer) session.getAttribute("VisitorID");
		
		
		EventSingUpService regEvent = new EventSingUpService();

        try{
    		boolean res = regEvent.registerInEvent(IdVisitor, IdEvent);
    		if (res){
    			session.setAttribute("Session", 4);
                ListEventServlet les = new ListEventServlet();
                les.sendListEventvisitor(request, response); 
    		}
   
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
	}

}
